package com.seafood.common;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页响应结果类
 */
@Data
public class PageResult<T> {
    
    private List<T> content;          // 数据内容
    private Long totalElements;       // 总记录数
    private Integer totalPages;       // 总页数
    private Integer currentPage;      // 当前页号（从0开始）
    private Integer size;             // 每页大小
    private Boolean first;            // 是否第一页
    private Boolean last;             // 是否最后一页
    private Boolean hasNext;          // 是否有下一页
    private Boolean hasPrevious;      // 是否有上一页
    
    public PageResult() {}
    
    public PageResult(List<T> content, Long totalElements, Integer totalPages, 
                     Integer currentPage, Integer size, Boolean first, Boolean last) {
        this.content = content;
        this.totalElements = totalElements;
        this.totalPages = totalPages;
        this.currentPage = currentPage;
        this.size = size;
        this.first = first;
        this.last = last;
        this.hasNext = !last;
        this.hasPrevious = !first;
    }
    
    /**
     * 创建分页结果
     */
    public static <T> PageResult<T> of(List<T> content, Long totalElements, Integer totalPages, 
                                      Integer currentPage, Integer size, Boolean first, Boolean last) {
        return new PageResult<>(content, totalElements, totalPages, currentPage, size, first, last);
    }
    
    /**
     * 空分页结果
     */
    public static <T> PageResult<T> empty() {
        return new PageResult<>(new ArrayList<>(), 0L, 0, 0, 0, true, true);
    }
}